from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.contrib.auth.models import User
from .models import new ,tool_beiwang,tool_user_zhanneixin


@admin.register(tool_beiwang)
class tool_beiwangAdmin(admin.ModelAdmin):
    list_display = ('title','addtime','add_user')

@admin.register(tool_user_zhanneixin)
class tool_user_zhanneixinAdmin(admin.ModelAdmin):
    list_display = ('title','addtime','add_user')





class CustomUserAdmin(BaseUserAdmin):
    list_display = ('username', 'email', 'full_name', 'is_active', 'date_joined')
    list_filter = ('is_active', 'is_superuser', 'is_staff', 'groups')
    search_fields = ('username', 'first_name', 'last_name', 'email')
    ordering = ('username',)
    filter_horizontal = ('groups', 'user_permissions',)

    def full_name(self, obj):
        return f"{obj.last_name}{obj.first_name}"
    full_name.short_description = '姓名'  # 设置列标题
    full_name.admin_order_field = 'last_name'  # 可选，设置排序字段

# 重新注册User模型，使用自定义的admin类
admin.site.unregister(User)
admin.site.register(User, CustomUserAdmin)


@admin.register(new)
class NewAdmin(admin.ModelAdmin):
    list_display = ('title','addtime','faburen')
    list_filter = ('title', 'addtime')
    search_fields = ('kehu', 'faburen')
    ordering = ('-addtime',)

